package com.atguigu.day73_demo;


import java.util.concurrent.*;

/**
 * @auther zzyy
 * @create 2024-08-07 11:39
 */
public class MyThreadPoolDemo {
    public static void main(String[] args) {

        //模拟N个顾客进入银行办理业务（请求线程），
        ThreadPoolExecutor threadPool= new ThreadPoolExecutor(5, 10, 5, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
        for (int i = 1; i <= 30; i++) {
            int number = i;
            threadPool.execute(() -> {
                System.out.println(Thread.currentThread().getName() + "给第" + number + "个人办理业务");
                //暂停几秒钟线程
//                try {
//                    TimeUnit.SECONDS.sleep(10);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
            });
        }
        threadPool.shutdown();
    }
}
        /*//模拟20个顾客进入银行办理业务（请求线程），
        //  private static void initPool() {
        ExecutorService threadPool = Executors.newFixedThreadPool(5);
        //ExecutorService threadPool = Executors.newSingleThreadExecutor();
        //  ExecutorService threadPool = Executors.newCachedThreadPool();
        for (int i = 1; i <= 55; i++) {
            int number = i;
            threadPool.execute(() -> {
                System.out.println(Thread.currentThread().getName() + "给第" + number + "个人办理业务");
                //暂停几秒钟线程
//                try {
//                    TimeUnit.SECONDS.sleep(10);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
            });
        }
        threadPool.shutdown();
    }
}*/

class ShareMyData {
    int number = 5;
}